package com.hx.xiao.controller;

import com.hx.xiao.entity.Hou;
import com.hx.xiao.entity.Su;
import com.hx.xiao.service.IHouService;
import com.hx.xiao.service.ISuService;
import com.hx.xiao.utils.Code;
import com.hx.xiao.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/piyaoh/su")
public class SuController {
    @Autowired
    private ISuService iSuService;

    @PostMapping("/add")
    public R addSu(@RequestBody Su su){
        int i = iSuService.addSu(su);
        if (i>0){
            return new R(Code.SAVE_OK,"添加成功");
        }else {
            return new R(Code.SAVE_ERRO,"添加失败");
        }
    }

    @GetMapping("/del/{uid}/{xid}")
    public R  delSu(@PathVariable Integer uid,@PathVariable Integer xid){
        int i = iSuService.delSu(uid,xid);
        if (i>0){
            return new R(Code.DELETE_OK,"取消收藏成功");
        }else {
            return new R(Code.DELETE_ERRO,"取消收藏失败");
        }
    }

    @GetMapping("/sel/{uid}/{xid}")
    public R  selectSu(@PathVariable Integer uid,@PathVariable Integer xid){
        Su su = iSuService.selectSu(uid, xid);
        if (su!=null){
            return new R(Code.GET_OK,su,"查询成功");
        }else {
            return new R(Code.GET_ERRO,"查询失败");
        }
    }

    @GetMapping("/find/{id}")
    public R findByID(@PathVariable Integer id){
        List<Map> byId = iSuService.findById(id);
        if (byId!=null){
            return new R(Code.GET_OK,byId,"查询成功");
        }else {
            return new R(Code.GET_ERRO,"查询失败");
        }
    }
    @GetMapping("/findtop10")
    public R findTop(Integer hid){
        List<Map> findtop10 = iSuService.findtop10(hid);
        if (findtop10!=null){
            return new R(Code.GET_OK,findtop10,"查询成功");
        }else {
            return new R(Code.GET_ERRO,"查询失败");
        }
    }
}
